import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';

// 相册指示器
class XinDongCommonYeMianIndicator extends StatelessWidget {
  // 当前选中下标
  final int currentIndex;

  // 指示器的个数
  final int totalCount;

  // 普通的颜色
  final Color normalColor;

  // 选中的颜色
  final Color selectedColor;

  // 背景颜色
  static const Color backgroundColor = DZColors.clear;

  // 点的大小
  static const double size = 6.0;

  // 点的间距
  static const double spacing = 8.0;

  // 构造函数
  const XinDongCommonYeMianIndicator({
    Key? key,
    required this.currentIndex,
    required this.totalCount,
    this.normalColor = Colors.grey,
    this.selectedColor = DZColors.mainColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(4),
      decoration: BoxDecoration(
        color: backgroundColor,
        borderRadius: BorderRadius.circular(10),
      ),
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: new List<Widget>.generate(totalCount, (int index) {
          return _buildIndicator(index, totalCount);
        }),
      ),
    );
  }

  // 点的Widget
  Widget _buildIndicator(int index, int yemianCount) {
    // 是否是当前页面被选中
    bool isCurrentYeMianSelected = index == currentIndex;

    return new Container(
      width: size + spacing,
      child: new Center(
        child: new Material(
          color: isCurrentYeMianSelected ? selectedColor : normalColor,
          type: MaterialType.circle,
          child: new Container(
            width: size,
            height: size,
          ),
        ),
      ),
    );
    // return new Container(
    //   width: size + spacing,
    //   child: new Center(
    //     child: new Material(
    //       color: isCurrentYeMianSelected ? selectedColor : normalColor,
    //       type: MaterialType.circle,
    //       child: new Container(
    //         width: size,
    //         height: size,
    //         alignment: Alignment.center,
    //         child: Text('${index+1}',style: TextStyle(fontSize: 8, color: isCurrentYeMianSelected == false ? selectedColor : normalColor),),
    //       ),
    //     ),
    //   ),
    // );
  }
}
